arrays
Arrays#
Author: @Fatmasiam
Arrays : #
Onedimensional Arrays: ⏬#
Objects allow you to store keyed collections of values. That’s fine.
But quite often we find that we need an ordered collection, where we have a 1st, a 2nd, a 3rd element and so on.
For example, we need that to store a list of something: users, goods, HTML elements etc.
It is not convenient to use an object here, because it provides no methods to manage the order of elements. We can’t insert a new property “between” the existing ones. Objects are just not meant for such use.
There exists a special data structure named Array, to store ordered collections.
What is ARRAYS means :#
Arrays : Are single variables used to store ordered and different kind of elements(collections).
SO : the array variable can hold more than one value at a time.
Array Declaration : #
We have two ways to create(declare) empty array
Almost all the time, the second syntax is used. and We can supply initial elements in the brackets:
Array elements are numbered, starting with zero. [This thing called indexing]#
- We can get an element by its number in square brackets:
- We can replace an element:
- …Or add a new one to the array:
The total count of the elements in the array is its
length:
The Array can store elements of any type.#
- For Example:
Manipulate Arrays : #
- arrays are mutable So array state can be modified after it is created. let's see the following example:
Multidimensional Arrays : ⏬#
Arrays can have items that are also arrays. We can use it for multidimensional arrays, for example to store matrices: